/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.pdx.cs.guavadata.query;

import edu.pdx.cs.guavadata.Channel;
import edu.pdx.cs.guavadata.Transform;
import edu.pdx.cs.guavadata.domain.Domain;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 *
 * @author VuTran
 */
public class AddTable extends Operator {

    public boolean enforcePrimaryKey;
    private String table;
    private List<String> columns;
    private List<String> keys;
    private List<Domain> domains;

    public AddTable(String table) {
        this.table = table;
        this.columns = new ArrayList<String>();
        this.domains = new ArrayList<Domain>();
        this.keys = new ArrayList<String>();
        this.parent = null;
        this.enforcePrimaryKey = true;
    }

    public AddTable(String table, Collection<String> columns, Collection<Domain> domains, Collection<String> keys) {
        this.table = table;
        this.columns = new ArrayList<String>(columns);
        this.domains = new ArrayList<Domain>(domains);
        this.keys = new ArrayList<String>(keys);
        this.parent = null;
        this.enforcePrimaryKey = true;

        // Dummy check
        try {
            if (columns.size() != domains.size())
                throw new Exception("Number of columns does not match number of domains in Add Table statement.");
        } catch (Exception e) {
            System.err.println("ERROR: " + e.toString());
        }
    }

    @Override
    public boolean isQuery() {
        return false;
    }

    @Override
    public SqlText visit(Provider qv) {
        return qv.transform(this);
    }

    @Override
    public void visit(Transform t, Command c) {
        t.expand(this, c);
    }

    @Override
    public void visit(Channel c, String table) {
        c.mapAliases(this, table);
    }



    public void addColumn(String column, Domain domain, boolean pk) {
        this.columns.add(column);
        this.domains.add(domain);
        if (pk)
            this.keys.add(column);
    }

    public String getTable() {
        return this.table;
    }

    /**
     * @param table the table to set
     */
    public void setTable(String table) {
        this.table = table;
    }

    /**
     * @return the columns
     */
    public List<String> getColumns() {
        return columns;
    }

    /**
     * @param columns the columns to set
     */
    public void setColumns(List<String> columns) {
        this.columns = columns;
    }

    /**
     * @return the keys
     */
    public List<String> getKeys() {
        return keys;
    }

    /**
     * @param keys the keys to set
     */
    public void setKeys(List<String> keys) {
        this.keys = keys;
    }

    /**
     * @return the domains
     */
    public List<Domain> getDomains() {
        return domains;
    }

    /**
     * @param domains the domains to set
     */
    public void setDomains(List<Domain> domains) {
        this.domains = domains;
    }

    @Override
    public void notifyChange(Operator old, Operator newOp) {
        throw new UnsupportedOperationException("The method or operation is not implemented.");
    }

    @Override
    public Operator clone() {
        return new AddTable(table, columns, domains, keys);
    }

}
